#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 41

int main() {
    FILE *fp;
    char words[MAX];
    if ((fp = fopen("test", "a+")) == NULL) {
        fprintf(stderr, "Open file fail!\n");
        exit(EXIT_FAILURE);
    }
    while (fscanf(stdin, "%40s", words) == 1 && words[0] != '#') {
        fprintf(fp, "%s\n", words);
    }
    rewind(fp);
    while (fscanf(fp, "%s", words) == 1) {
        puts(words);
    }
    puts("Done!");
    if (fclose(fp) != 0) {
        fprintf(stderr, "Close file fail!\n");
    }
    return 0;
}